<template>
	<view class="mainPage">
		<view class="banner"><u-image width="750" height="400" :src="appletImgUrl+'classBanner.png'" mode="aspectFill"></u-image></view>
       <view class="list">
		   <view class="li" @tap="jumpDeta()">
			   <view class="li-left"><u-image width="140" height="140" :src="appletImgUrl+'newpic.png'"></u-image></view>
			   <view class="li-right">
				   <view class="li-right-top">开学第一课，多彩生活迎亚运</view>
				   <view class="li-right-bottom"><u-icon name="clock" color="#ccc" size="28"></u-icon>2023.09.22</view>
			   </view>
		   </view>
		   <view class="li">
		   			   <view class="li-left"><u-image width="140" height="140" :src="appletImgUrl+'newpic.png'"></u-image></view>
		   			   <view class="li-right">
		   				   <view class="li-right-top">开学第一课，多彩生活迎亚运</view>
		   				   <view class="li-right-bottom"><u-icon name="clock" color="#ccc" size="28"></u-icon>2023.09.22</view>
		   			   </view>
		   </view>
	   </view>
		
		<u-loadmore :status="status" />
	
	</view>
</template>

<script>
import {appletImgUrl} from "@/common/config.js"
	export default {
		data() {
			return {
				appletImgUrl:appletImgUrl,
				show: false,
				mode: "range",
				couponInfo:{
					currentAmount:0,
					userId:"",
					weeksAmount:0
				},
				recordList:[],
				queryData:{
					 bzType:"",
					 endTime:"",
					 pageNo:1,
					 pageSize:10,
					startTime:""
				},
				status:"loadmore",
				pageTotal:1,
				navList:[{name:"按日",type:"1"},{name:"按月",type:"2"}],
				cur:0,
				currentTime:"",//今天
				timeType:"1",//日期时间类型
				public:{
					 startTime:"",
					 endTime:""
				},
				count:0
			}
		},
		onLoad(option){
			this.queryData.bzType=option.type;
		   this.getTime()
		   this.recordList=[];
		   this.getMiHuiCouponInfo();
		   this.getMiHuiRecordList();
		},
		onShow() {
		},
		onReachBottom(){
			if(this.count>=10){
				this.status = 'loading';
				this.queryData.pageNo++
				this.getMiHuiRecordList();
			}else{
				this.status = 'nomore'
			}
			
		},
		onPullDownRefresh(){
			
		},
		methods: {
			getTime(){
				let now = new Date();
				let year = now.getFullYear(); // 年
				let month = now.getMonth() + 1; // 月
				let date = now.getDate(); // 日
				var lastDate = new Date(year, month , 0).getDate(); //获取当月最后一日
				if(month<10){
							   month="0"+month;
				}
				if(date<10){
							   date="0"+date;
				}
				//默认按日(今天)
				if(this.timeType==1){
					this.public.startTime=year+"-"+month+"-"+date+" 00:00:00";
					this.public.endTime=year+"-"+month+"-"+date+" 23:59:59";
					this.currentTime=month+"月"+date+"日"+" 今天";
				}else{
					this.public.startTime=year+"-"+month+"-01"+" 00:00:00";
					this.public.endTime=year+"-"+month+"-"+lastDate+" 23:59:59";
					this.currentTime=year+"-"+month+"-01"+"至"+year+"-"+month+"-"+lastDate;
				}
				
				this.queryData.startTime=this.public.startTime;
				this.queryData.endTime=this.public.endTime;
				
			},
			openData() {
				this.show = true;
			},
			change(e) {
				console.log(e);
				this.public.startTime=e.startDate+' '+'00:00:00';
				this.public.endTime=e.endDate+' '+'23:59:59';
				
				this.queryData.startTime=this.public.startTime;
				this.queryData.endTime=this.public.endTime;
				this.currentTime=e.startDate+"至"+e.endDate;
				this.queryData.pageNo=1;
				this.pageTotal=1;
				this.recordList=[];
				this.count=0;
				this.getMiHuiRecordList();
			},
			getMiHuiCouponInfo(){
				this.$u.get('usermhqwallet/info').then(res => {
					console.log(res);
					this.couponInfo=res;
				});
			},
			getMiHuiRecordList(){
				this.$u.post('usermhqwallet/walletLogList',this.queryData).then(res => {
					console.log(res);
					this.recordList=[...res.list,...this.recordList];
					this.count=res.list.length;
					if(this.count>=10){
						this.status = 'loading';
					}else{
						this.status = 'nomore';
					}
				});
			},
			jumpDeta(){
				uni.navigateTo({
					url: '/pages/other/classRoom/classDetail'
				});
			},
			tabEvent(type,index){
				this.cur=index;
				this.timeType=type;
				this.getTime();
				this.queryData.pageNo=1;
				this.recordList=[];
				this.count=0;
				this.getMiHuiRecordList();
			}
		}
	}
</script>

<style lang="scss">
	.mainPage{
		background-color: #f1f3f5;
	}
	.banner{
		margin-bottom: 30rpx;
	}
	.list{
		.li{
			padding-left: 30rpx;
			padding-right: 30rpx;
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
		
			background-color: #fff;
			padding-bottom: 20rpx;
			padding-top: 20rpx;
			border-bottom: 2rpx solid #eee;
			.li-left{
				margin-right: 20rpx;
				
			}
			.li-right{
				position: relative;
				.li-right-top{
					padding-top: 20rpx;
					font-size: 28rpx;
					font-weight: bold;
				}
				.li-right-bottom{
					position: absolute;
					left: 0;
					bottom:20rpx;
				}
			}
		}
	}
</style>